// pages/my_shop_dec/my_shop_dec.js
const app = getApp();
const $get_api = require('../../common/api').HTTP;
const wx_auth = require('../../common/wx_auth') //微信授权js
const until = require('../../utils/util') //引用工具
// 富文本插件
const wxParse = require("../../wxParse/wxParse.js");
const now_page = "my_shop_dec/"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        activeList:[ ],
        swiperCurrent: 0, //当前导航点
        sp_info:{
            id:1,name:"商品名称1",sp_dec:'ncdsklnclksdna',price:0.15,sp_num:'ml'
        },
        until:until,
        now_page:now_page,
        total_price:0, //商品总价
        unit_price:0, //商品单价 
        input_num: 1,  // input默认是1  
        minusStatus:'disabled',  // 使用data数据对象设置样式名
        wx_icon:app.imgUrl + now_page + "wx_icon.png"+ app.version,
        tel_icon:app.imgUrl + now_page + "tel_icon.png"+ app.version,
        sp_id:null, 
        sp_num:null, 
        modalHidden:true, //显示弹窗变量
        wx_ewm:app.imgUrl + now_page + "wx_icon.png"+ app.version,
        phone:"",
        isLoginBtn:true,
        share_route_obj:{},
        share_title:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // console.log(options,"options.id");
        let that = this;
        that.data.sp_id = options.id;
        let obj = {id:that.data.sp_id} //分享参数对象
        that.data.share_route_obj = obj
      // if(that.data.sp_id == ""){
      //   that.data.sp_id = wx.getStorageSync('sp_id')
      // }else{
      //   wx.setStorageSync('sp_id', that.data.sp_id)
      // }
       console.log(that.data.sp_id);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow(options) {
        let that = this;
        that.data.login_status = wx_auth.checkToken()
 
        if(!that.data.login_status){
            wx_auth.authApply(options,'','',that.data.share_route_obj,0);  //授权登录分享跳转路由（不弹出头像设置）1为弹出
        }
        if(wx_auth.checkToken(1)){
          this.data.isLoginBtn = false;
          that.pageOnload();
          that.setData({
              isLoginBtn:this.data.isLoginBtn,
          })
      }
      
        
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        let that = this;
        // 构建页面参数
        let path = until.get_url();
        return until.wx_share(that.data.share_title,path,null,that.data.share_route_obj)
    },
    shopListDec:function(){
        let that = this;
        $get_api.shopChildList({ a:1
        }).then(r => { 
            let data = r.data.data;
            console.log(data,"data");
            if (res.data[0].content.length > 0) {
                
              }
              console.log(res.data[0].banner)
        })
    },
    /**
   * 显示弹窗
   */
  show_wx: function() {
    this.setData({
      modalHidden: false
    })
  },
  
  /**
   *  点击确认
   */
  modalConfirm: function() {
    // do something
    this.setData({
      modalHidden: true
    })
  },
    call_num:function(){
      let that = this
      let phone = that.data.phone
      wx.makePhoneCall({
        phoneNumber: phone,  // 这里填写要拨打的电话号码
        success: function() {
            console.log("拨打电话成功!")
        },
        fail: function() {
            console.log("拨打电话失败!")
        }
      })
    },
     
    pageOnload:function() {
        let that = this;
        let shop_id = that.data.sp_id;
        $get_api.getActivityInfoDesc({ 
            id:shop_id,
        }).then(r => { 
            let data = r.data.data;
            console.log(data,"pageOnload-data");
            wxParse.wxParse('content', 'html', data.describe, that, 0);
            that.data.phone = data.phone
            that.data.wx_ewm = data.qr_images
            that.data.share_title = data.title
            // that.data.sp_id = data.id
            that.setData({
              wx_ewm:that.data.wx_ewm,
              is_open:data.is_open
            })
        })
    },
    //去报名页面
    goto_baoming_page:function(){
      let that = this
      wx.navigateTo({
        url: '../apply_join/apply_join?id='+that.data.sp_id,
      })
    }
})